import torch

# 使用reshape 方法设置张量的形状大小
a = torch.arange(12.0).reshape(3, 4)
print(torch.arange(12.0))
print(a)
print(torch.reshape(input = a, shape = (2, -1)))


# 改变张量的形状 使用 tensor.resize_()方法
print(a.resize_(2, 6))

# 使用 resize_as_(b)   使a改变成和b一样形状的张量
b = torch.arange(10, 19).reshape(3, 3)
a.resize_as_(b)
print(b)
print(a)


# 使用 squeeze 得到维度最小的新张量
a = torch.arange(12.0).reshape(2, 6)
b = torch.unsqueeze(a, dim = 0)
print("b.shape", b.shape)
c = b.unsqueeze(dim = 3)
print("c.shape", c.shape)
d = torch.squeeze(c)
print("d.shape", d.shape)
e = torch.squeeze(c, dim = 0)
print("e.shape", e.shape)


